import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_nb_net/flutter_net.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wechat_kit/wechat_kit.dart';
import 'package:tracker/common/log/x_logger.dart';
import 'package:tracker/common/pay/ali_pay_utils.dart';
import 'package:tracker/common/pay/model/order_info_req.dart';
import 'package:tracker/common/pay/wxpay_utils.dart';
import 'package:tracker/common/widget/pay_dialog_widget.dart';
import 'package:tracker/pages/home/flowcard/model/card_packages_resp.dart';
import 'package:tracker/pages/home/vip/enum/buy_type.dart';
import 'package:tracker/pages/home/vip/model/vip_info_resp.dart';
import 'package:tracker/provider/global_provider.dart';
import 'package:tracker/theme/app_theme.dart';
import 'package:tracker/utils/color_utils.dart';
import 'package:tracker/utils/num_utils.dart';
import 'package:tracker/utils/toast_utils.dart';

class VipPage extends ConsumerStatefulWidget {
  const VipPage({super.key});

  @override
  ConsumerState<VipPage> createState() => _VipPageState();
}

class _VipPageState extends ConsumerState<VipPage> {
  bool showLoading = false;

  /// 所有套餐
  VipInfoData vipInfoData = VipInfoData();

  /// 允许展示的套餐
  List<VipPackage> vipPackageList = [];

  /// 当选选中的购买类型
  BuyType selectedBuyType = BuyType.deviceRenewal;

  /// 选中的套餐下标
  int selectedPackageIndex = 0;

  /// 套餐配置，允许展示的套餐
  final List<BuyType> _buyTypeList = [
    BuyType.deviceRenewal,
  ];

  PayDialogWidget payDialogWidget = PayDialogWidget();

  final alipayUtils = AliPayUtils();
  final wxpayUtils = WxpayUtils();

  Future<void> _fetchDeviceInfo() async {
    await ref.read(deviceInfoProvider.notifier).refresh(() {});
    setState(() {
      showLoading = false;
    });
  }

  _fetchVipInfo() async {
    final deviceInfo = ref.watch(deviceInfoProvider);
    ToastUtils.showLoading();
    final res = await get<VipInfoResp, VipInfoResp>('', decodeType: VipInfoResp());
    res.when(
        success: (resp) {
          ToastUtils.dismissLoading();
          if (resp.code == 200) {
            setState(() {
              vipInfoData = resp.data!;
              // 只展示_packageConfigList中配置的套餐
              vipPackageList = resp.data!.packages!.where((element) {
                return _buyTypeList.any((buyType) => buyType.value == element.packageType);
              }).toList();
            });
          } else {
            ToastUtils.showToast(resp.msg ?? '获取套餐信息失败');
          }
        },
        failure: (String msg, int code) {});
  }

  _showLoading() {
    return Center(
      child: CircularProgressIndicator(
        color: AppTheme.themeConfig.primaryColor,
      ),
    );
  }

  Widget _buildBodyView() {
    return Stack(fit: StackFit.expand, children: [
      SingleChildScrollView(
          child: Column(mainAxisAlignment: MainAxisAlignment.start, children: [
        const SizedBox(height: 16),
        // 设备信息
        _buildDeviceInfoView(),
        const SizedBox(height: 16),
        // 购买类型标签
        _buildBuyTypeTabView(),
        const SizedBox(height: 16),
        Container(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Text(
              '请选择套餐',
              style: TextStyle(color: AppTheme.themeConfig.primaryTextColor, fontSize: 17, fontWeight: FontWeight.bold),
            )),
        const SizedBox(height: 16),
        // 套餐列表
        _buildVipPackageListView(),
        const SizedBox(height: 16),
        // 套餐内容
        _buildPackageContentView(),
        const SizedBox(height: 90),
      ])),
      // 底部按钮
      _buildBottomBtn(),
    ]);
  }

  _buildDeviceInfoView() {
    final deviceInfo = ref.watch(deviceInfoProvider);
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16),
      padding: const EdgeInsets.all(20),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [
            AppTheme.themeConfig.primaryColor,
            AppTheme.themeConfig.primaryColor.withOpacity(0.8),
          ],
        ),
        borderRadius: BorderRadius.circular(20),
        boxShadow: [
          BoxShadow(
            color: AppTheme.themeConfig.primaryColor.withOpacity(0.3),
            blurRadius: 12,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 标题
          Row(
            children: [
              Container(
                padding: const EdgeInsets.all(8),
                decoration: BoxDecoration(
                  color: Colors.white.withOpacity(0.2),
                  borderRadius: BorderRadius.circular(10),
                ),
                child: const Icon(Icons.devices, color: Colors.white, size: 20),
              ),
              const SizedBox(width: 12),
              const Text(
                '设备信息',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18,
                  fontWeight: FontWeight.w700,
                ),
              ),
              const Spacer(),
              // 申请退款
              GestureDetector(
                onTap: () {
                  ToastUtils.showSimpleBottomDialog(
                    context,
                    title: '申请退款',
                    content: '尊敬的用户，如您已购买套餐，购买成功之后可以申请退款，客服人员将及时为您处理。',
                    confirmTitle: '好的',
                  );
                },
                child: Container(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 12,
                    vertical: 6,
                  ),
                  decoration: BoxDecoration(
                    color: Colors.white.withOpacity(0.2),
                    borderRadius: BorderRadius.circular(20),
                    border: Border.all(
                      color: Colors.white.withOpacity(0.5),
                      width: 1,
                    ),
                  ),
                  child: const Text(
                    '申请退款',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 12,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ),
              ),
            ],
          ),
          const SizedBox(height: 16),
          // 设备信息列表
          _buildInfoRow(Icons.phone_android, '设备名称', deviceInfo.deviceName ?? ''),
          const SizedBox(height: 12),
          _buildInfoRow(Icons.qr_code, '设备号', deviceInfo.imei ?? ''),
          const SizedBox(height: 12),
          _buildInfoRow(Icons.access_time, '到期时间', _buildExpireText()),
        ],
      ),
    );
  }

  Widget _buildInfoRow(IconData icon, String label, String value) {
    return Row(
      children: [
        Icon(icon, color: Colors.white.withOpacity(0.9), size: 16),
        const SizedBox(width: 8),
        Text(
          '$label: ',
          style: TextStyle(
            color: Colors.white.withOpacity(0.9),
            fontSize: 14,
            fontWeight: FontWeight.w500,
          ),
        ),
        Expanded(
          child: Text(
            value,
            style: const TextStyle(
              color: Colors.white,
              fontSize: 14,
              fontWeight: FontWeight.w600,
            ),
            overflow: TextOverflow.ellipsis,
          ),
        ),
      ],
    );
  }

  String _buildExpireText() {
    var text = '';
    // 设备续期
    if (vipInfoData.deviceRenewal != null) {
      // 判断是否到期
      if (vipInfoData.deviceRenewal?.expired == true) {
        text = '设备未激活或已到期，请购买套餐';
      } else {
        text = '到期时间：${vipInfoData.deviceRenewal?.expireTime ?? ''}';
      }
    }
    return text;
  }

  Widget _buildBuyTypeTabView() {
    if (vipPackageList.isEmpty) {
      return Container();
    }
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16),
      child: Wrap(
        spacing: 12,
        runSpacing: 12,
        alignment: WrapAlignment.center,
        children: vipPackageList.map((vipPackage) {
          final isSelected = selectedBuyType.value == vipPackage.packageType;
          return GestureDetector(
            onTap: () {
              setState(() {
                selectedBuyType = BuyType.values.firstWhere((e) => e.value == vipPackage.packageType);
                selectedPackageIndex = 0;
              });
            },
            child: Container(
              padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
              decoration: BoxDecoration(
                gradient: isSelected
                    ? LinearGradient(
                        begin: Alignment.topLeft,
                        end: Alignment.bottomRight,
                        colors: [
                          AppTheme.themeConfig.primaryColor,
                          AppTheme.themeConfig.primaryColor.withOpacity(0.8),
                        ],
                      )
                    : null,
                color: isSelected ? null : Colors.white,
                borderRadius: BorderRadius.circular(25),
                border: Border.all(
                  color: isSelected ? AppTheme.themeConfig.primaryColor : Colors.grey.shade300,
                  width: isSelected ? 2 : 1,
                ),
                boxShadow: isSelected
                    ? [
                        BoxShadow(
                          color: AppTheme.themeConfig.primaryColor.withOpacity(0.3),
                          blurRadius: 8,
                          offset: const Offset(0, 2),
                        ),
                      ]
                    : null,
              ),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Icon(
                    isSelected ? Icons.check_circle : Icons.circle_outlined,
                    color: isSelected ? Colors.white : Colors.grey.shade500,
                    size: 18,
                  ),
                  const SizedBox(width: 8),
                  Text(
                    vipPackage.packageTypeName ?? '',
                    style: TextStyle(
                      color: isSelected ? Colors.white : AppTheme.themeConfig.primaryTextColor,
                      fontSize: 14,
                      fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
                    ),
                  ),
                ],
              ),
            ),
          );
        }).toList(),
      ),
    );
  }

  /// 套餐列表
  Widget _buildVipPackageListView() {
    if (vipPackageList.isEmpty) {
      return Container();
    }
    final vipPackage = vipPackageList.firstWhere((element) => element.packageType == selectedBuyType.value);
    final List<VipPackageInfo> packageInfos = vipPackage.packageInfos ?? [];
    
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16),
      child: GridView.builder(
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        itemCount: packageInfos.length,
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2,
          crossAxisSpacing: 12,
          mainAxisSpacing: 12,
          childAspectRatio: 1.1,
        ),
        itemBuilder: (context, index) {
          final packageInfo = packageInfos[index];
          final isSelected = selectedPackageIndex == index;
          final discount = packageInfo.originalPrice != null && packageInfo.price != null
              ? ((1 - packageInfo.price! / packageInfo.originalPrice!) * 100).toInt()
              : 0;
          
          return GestureDetector(
            onTap: () {
              setState(() {
                selectedPackageIndex = index;
              });
            },
            child: Container(
              decoration: BoxDecoration(
                gradient: isSelected
                    ? LinearGradient(
                        begin: Alignment.topLeft,
                        end: Alignment.bottomRight,
                        colors: [
                          AppTheme.themeConfig.primaryColor.withOpacity(0.15),
                          AppTheme.themeConfig.primaryColor.withOpacity(0.05),
                        ],
                      )
                    : null,
                color: isSelected ? null : Colors.white,
                borderRadius: BorderRadius.circular(16),
                border: Border.all(
                  color: isSelected ? AppTheme.themeConfig.primaryColor : Colors.grey.shade300,
                  width: isSelected ? 2 : 1,
                ),
                boxShadow: [
                  BoxShadow(
                    color: isSelected 
                        ? AppTheme.themeConfig.primaryColor.withOpacity(0.2)
                        : Colors.black.withOpacity(0.05),
                    blurRadius: isSelected ? 12 : 6,
                    offset: Offset(0, isSelected ? 4 : 2),
                  ),
                ],
              ),
              padding: const EdgeInsets.all(12),
              child: Stack(
                children: [
                  // 折扣标签
                  if (discount > 0)
                    Positioned(
                      top: 0,
                      right: 0,
                      child: Container(
                        padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
                        decoration: BoxDecoration(
                          gradient: LinearGradient(
                            colors: [Colors.red.shade400, Colors.red.shade600],
                          ),
                          borderRadius: BorderRadius.circular(8),
                        ),
                        child: Text(
                          '$discount%OFF',
                          style: const TextStyle(
                            color: Colors.white,
                            fontSize: 10,
                            fontWeight: FontWeight.w700,
                          ),
                        ),
                      ),
                    ),
                  
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      // 选中图标
                      if (isSelected)
                        Container(
                          padding: const EdgeInsets.all(4),
                          decoration: BoxDecoration(
                            color: AppTheme.themeConfig.primaryColor,
                            shape: BoxShape.circle,
                          ),
                          child: const Icon(Icons.check, color: Colors.white, size: 16),
                        ),
                      if (isSelected) const SizedBox(height: 8),
                      
                      // 套餐名称
                      Text(
                        packageInfo.name ?? '',
                        style: TextStyle(
                          color: isSelected 
                              ? AppTheme.themeConfig.primaryColor
                              : AppTheme.themeConfig.primaryTextColor,
                          fontSize: 14,
                          fontWeight: FontWeight.w700,
                        ),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        textAlign: TextAlign.center,
                      ),
                      
                      const SizedBox(height: 8),
                      
                      // 价格
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Text(
                            '¥',
                            style: TextStyle(
                              color: isSelected 
                                  ? AppTheme.themeConfig.primaryColor
                                  : AppTheme.themeConfig.primaryTextColor,
                              fontSize: 14,
                              fontWeight: FontWeight.w700,
                            ),
                          ),
                          Text(
                            '${packageInfo.price}',
                            style: TextStyle(
                              color: isSelected 
                                  ? AppTheme.themeConfig.primaryColor
                                  : AppTheme.themeConfig.primaryTextColor,
                              fontSize: 22,
                              fontWeight: FontWeight.w900,
                            ),
                          ),
                        ],
                      ),
                      
                      const SizedBox(height: 4),
                      
                      // 原价
                      Text(
                        '原价¥${packageInfo.originalPrice}',
                        style: TextStyle(
                          color: AppTheme.themeConfig.infoTextColor,
                          fontSize: 11,
                          decoration: TextDecoration.lineThrough,
                          decorationColor: AppTheme.themeConfig.infoTextColor,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }

  /// 套餐内容
  Widget _buildPackageContentView() {
    if (vipPackageList.isEmpty) {
      return Container();
    }
    final vipPackage = vipPackageList.firstWhere((element) => element.packageType == selectedBuyType.value);
    final List<VipPackageInfo> packageInfos = vipPackage.packageInfos ?? [];
    if (packageInfos.isEmpty) {
      return Container();
    }
    final packageInfo = packageInfos[selectedPackageIndex];
    return Container(
      width: double.infinity,
      margin: const EdgeInsets.symmetric(horizontal: 16),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 8,
            offset: const Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            children: [
              Container(
                padding: const EdgeInsets.all(6),
                decoration: BoxDecoration(
                  color: AppTheme.themeConfig.primaryColor.withOpacity(0.1),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Icon(
                  Icons.description,
                  color: AppTheme.themeConfig.primaryColor,
                  size: 18,
                ),
              ),
              const SizedBox(width: 10),
              Text(
                '套餐说明',
                style: TextStyle(
                  color: AppTheme.themeConfig.primaryTextColor,
                  fontSize: 16,
                  fontWeight: FontWeight.w700,
                ),
              ),
            ],
          ),
          const SizedBox(height: 12),
          Container(
            width: double.infinity,
            padding: const EdgeInsets.all(12),
            decoration: BoxDecoration(
              color: AppTheme.themeConfig.greyBgColor,
              borderRadius: BorderRadius.circular(12),
            ),
            child: Text(
              packageInfo.description ?? '',
              style: TextStyle(
                color: AppTheme.themeConfig.secondaryTextColor,
                fontSize: 14,
                height: 1.5,
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildBottomBtn() {
    if (vipPackageList.isEmpty) {
      return Container();
    }
    final vipPackage = vipPackageList.firstWhere((element) => element.packageType == selectedBuyType.value);
    final List<VipPackageInfo> packageInfos = vipPackage.packageInfos ?? [];
    if (packageInfos.isEmpty) {
      return Container();
    }
    final packageInfo = packageInfos[selectedPackageIndex];
    // 已省多少钱
    final savePrice = NumUtils.formatNum(packageInfo.originalPrice! - packageInfo.price!);
    
    return Positioned(
      bottom: 0,
      left: 0,
      right: 0,
      child: Container(
        padding: const EdgeInsets.all(16),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: const BorderRadius.vertical(top: Radius.circular(24)),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1),
              blurRadius: 16,
              offset: const Offset(0, -4),
            ),
          ],
        ),
        child: SafeArea(
          child: GestureDetector(
            onTap: () {
              _showPayDialog();
            },
            child: Container(
              height: 56,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    AppTheme.themeConfig.primaryColor,
                    AppTheme.themeConfig.primaryColor.withOpacity(0.8),
                  ],
                ),
                borderRadius: BorderRadius.circular(28),
                boxShadow: [
                  BoxShadow(
                    color: AppTheme.themeConfig.primaryColor.withOpacity(0.4),
                    blurRadius: 12,
                    offset: const Offset(0, 4),
                  ),
                ],
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Icon(
                    Icons.shopping_cart,
                    color: Colors.white,
                    size: 24,
                  ),
                  const SizedBox(width: 12),
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '¥${packageInfo.price ?? ''} 立即购买',
                        style: const TextStyle(
                          color: Colors.white,
                          fontSize: 18,
                          fontWeight: FontWeight.w700,
                        ),
                      ),
                      Text(
                        '已省 $savePrice 元',
                        style: TextStyle(
                          color: Colors.white.withOpacity(0.9),
                          fontSize: 12,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  /// 购买弹窗
  _showPayDialog() {
    if (vipPackageList.isEmpty) {
      ToastUtils.showToast('未查询到套餐信息');
      return;
    }
    final vipPackage = vipPackageList.firstWhere((element) => element.packageType == selectedBuyType.value);
    if (vipPackage.packageInfos == null || vipPackage.packageInfos!.isEmpty) {
      ToastUtils.showToast('未查询到套餐信息');
      return;
    }
    final List<VipPackageInfo> packageInfos = vipPackage.packageInfos ?? [];
    if (packageInfos.isEmpty) {
      ToastUtils.showToast('未查询到套餐信息');
      return;
    }
    final packageInfo = packageInfos[selectedPackageIndex];
    payDialogWidget.showPayDialog(context, '${packageInfo.price}', onConfirm: (payType) {
      _handleBuy(payType);
    });
  }

  /// 购买
  _handleBuy(PayType payType) {
    if (vipPackageList.isEmpty) {
      ToastUtils.showToast('未查询到套餐信息');
      return;
    }
    final vipPackage = vipPackageList.firstWhere((element) => element.packageType == selectedBuyType.value);
    if (vipPackage.packageInfos == null || vipPackage.packageInfos!.isEmpty) {
      ToastUtils.showToast('未查询到套餐信息');
      return;
    }
    final List<VipPackageInfo> packageInfos = vipPackage.packageInfos ?? [];
    if (packageInfos.isEmpty) {
      ToastUtils.showToast('未查询到套餐信息');
      return;
    }
    // 支付方式
    final payAccount = PayUtils.getPayAccount(payType);
    final payTypeParams = PayUtils.getPayType(payType);
    final packageInfo = packageInfos[selectedPackageIndex];
    final orderInfoReq = OrderInfoReq(
      imei: vipInfoData.imei,
      payType: payTypeParams,
      payAccount: payAccount,
      orderType: 2,
      flowPackage: PackageInfo(
        packageCode: packageInfo.id.toString(),
        price: packageInfo.price,
        packageName: packageInfo.name,
        timeLength: packageInfo.durationNum,
        timeUnit: packageInfo.durationUnit.toString(),
        packageId: packageInfo.id,
        packageType: selectedBuyType.value,
      ),
    );
    XLogger.debug('orderInfoReq: ${orderInfoReq.toJson()}');
    if (payType == PayType.alipay) {
      alipayUtils.createOrder(orderInfoReq);
    } else if (payType == PayType.wechat) {
      wxpayUtils.createOrder(orderInfoReq);
    } else if (payType == PayType.wechatUnion) {
      wxpayUtils.createMiniAppOrder(orderInfoReq);
    }
  }

  @override
  void initState() {
    super.initState();
    setState(() {
      showLoading = true;
    });
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      await _fetchDeviceInfo();
      await _fetchVipInfo();
      wxpayUtils.registerWechatResp((resp) {
        if (resp is WechatLaunchMiniProgramResp) {
          XLogger.info('拉起小程序: ${resp.errorCode} ${resp.errorMsg}, isSuccessful: ${resp.isSuccessful}');
          XLogger.info('拉起小程序 exMsg: ${resp.extMsg}');
          if (resp.isSuccessful) {
            // 支付成功
            ToastUtils.showSimpleDialog(context,
                title: '提示', content: '套餐购买成功', confirmTitle: '好的', confirmCallback: () {});
            // 刷新套餐信息
            _fetchDeviceInfo();
            _fetchVipInfo();
          } else {
            // 支付失败
            ToastUtils.showToast('支付失败');
          }
        }
      });
    });
    alipayUtils.listenPay((resp) {
      XLogger.info('VIP支付结果：${resp.resultStatus}');
      if (resp.isSuccessful) {
        // 支付成功
        ToastUtils.showSimpleDialog(context,
            title: '提示', content: '套餐购买成功', confirmTitle: '好的', confirmCallback: () {});
        // 刷新套餐信息
        _fetchDeviceInfo();
        _fetchVipInfo();
      } else {
        // 支付失败
        ToastUtils.showToast('支付失败');
      }
    });
    // wxpayUtils.registerWechatResp((resp) {
    //   XLogger.info('支付结果：${resp.errorCode}, ${resp.errorMsg}');
    //   if (resp.isSuccessful) {
    //     // 支付成功
    //     // 支付成功
    //     ToastUtils.showSimpleDialog(
    //         context,
    //         title: '提示',
    //         content: '套餐购买成功',
    //         confirmTitle: '好的',
    //         confirmCallback: () {
    //         }
    //     );
    //     // 刷新套餐信息
    //     _fetchDeviceInfo();
    //     _fetchVipInfo();
    //   } else {
    //     // 支付失败
    //     ToastUtils.showToast('支付失败');
    //   }
    // });
  }

  @override
  void dispose() {
    super.dispose();
    alipayUtils.dispose();
    wxpayUtils.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          '购买套餐',
          style: TextStyle(color: Colors.white),
        ),
        centerTitle: true,
        backgroundColor: AppTheme.themeConfig.primaryColor,
        elevation: 0,
        iconTheme: const IconThemeData(color: Colors.white),
      ),
      backgroundColor: Colors.grey.shade100,
      body: showLoading ? _showLoading() : _buildBodyView(),
    );
  }
}

class VipPackageConfig {
  int packageType;
  String packageName;
  String packageProperty;
  VipPackageConfig({
    required this.packageType,
    required this.packageName,
    required this.packageProperty,
  });
}


